package com.mdyy.servlet;

import com.mdyy.util.HDFSUtil;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.OutputStream;

/**
 * 文件下载
 * @author Administrator
 *
 */
@WebServlet("/fileDownLoadServlet")
public class FileDownloadServlet extends HttpServlet {

    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {
        request.setCharacterEncoding("UTF-8");
        response.setCharacterEncoding("UTF-8");

        String fileName = request.getParameter("fileName");
        //解决中文乱码
        response.setHeader("Content-Disposition", "attachment;filename="
                + new String(fileName.getBytes("GB18030"),"ISO8859-1"));

        OutputStream out = response.getOutputStream();
        //文件下载
        HDFSUtil.downLoadFile(fileName, out);
    }

    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {

    }
}
